package co.fitstart.weapp.api.web.controller.coach;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.demo2do.core.entity.result.HttpResult;

import co.fitstart.weapp.api.service.MovementService;

/**
 * 
 * @author haiyan_xiao
 *
 */
@RestController
@RequestMapping("/coach")
public class MovementController {

    private static final Logger logger = LoggerFactory.getLogger(MovementController.class);

    @Autowired
    private MovementService movementService;

    /**
     * 
     * @param mobile
     * @param name
     * @return
     */
    @RequestMapping(value = "/movements", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE, params = "mobile")
    public HttpResult list(@RequestParam("mobile") String mobile, 
                           @RequestParam(value = "name", required = false) String name) {
        HttpResult httpResult = new HttpResult();
        
        try {
            httpResult.success().message("获取数据成功")
                                .data("movements", movementService.list(name));
        } catch (Exception e) {
            logger.error("#MovementController# list() error", e);
            httpResult.fail("500").message("加载数据失败");
        }
        
        return httpResult;
    }

    /**
     * 
     * @param mobile
     * @return
     */
    @RequestMapping(value = "/movement-groups", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE, params = "mobile")
    public HttpResult listGroup(@RequestParam("mobile") String mobile) {
        HttpResult httpResult = new HttpResult();
        
        try {
            httpResult.success().message("获取数据成功")
                                .data("groups", movementService.listGroup());
        } catch (Exception e) {
            logger.error("#MovementController# listGroup() error", e);
            httpResult.fail("500").message("加载数据失败");
        }
        
        return httpResult;
    }
}
